<?php require_once ("header.php"); ?>
<?php 
	//check admin status
	if($ad_check<1){
	header ("Location:../login.php?action=0");
	}
?>

<style type="text/css">
<!--
.style3 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 11px;
}
.style4 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 14px;
	font-weight: bold;
}
.style5 {color: #FFFFFF}
.style6 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px; color: #000000; }
.style7 {color: #000000}
-->
</style>
<?php
	//this is the engine of the FORM
	if (isset($_POST['Submit'])){
		$error=0;
		if ($_POST['dep']!=NULL){
			$dep=$_POST['dep'];
			$sql_get_code="SELECT dep_code FROM deparment WHERE dep_name='$dep'";
			$get_code=mysql_query($sql_get_code);
			$code=mysql_fetch_assoc($get_code);
			$dep=$code['dep_code'];
		} else { $error=1; }
		if ($_POST['course']!=NULL){
			$course=$_POST['course'];
		} else { $error=1; }
		if ($_POST['sem']!=NULL){
			$sem=$_POST['sem'];
		} else { $error=1; }
		if ($_POST['class']!=NULL){
			$class=$_POST['class'];
		} else { $error=1; }
		if ($_POST['start']!=NULL){
			$start=$_POST['start'];
		} else { $error=1; }
		if ($_POST['end']!=NULL){
			$end=$_POST['end'];
		} else { $error=1; }
		if ($_POST['t_start']!=NULL){
			$tstart=$_POST['t_start'];
		} else { $error=1; }
		if ($_POST['t_end']!=NULL){
			$tend=$_POST['t_end'];
		} else { $error=1; }
		if ($_POST['num']!=NULL){
			$num=$_POST['num'];
		} else { $error=1; }
		if ($_POST['sub']!=NULL){
			$sub=$_POST['sub'];
		} else { $error=1; }
		
		if ($error==0){
			$start="{$start} {$tstart}";
			$end="{$end} {$tend}";
			$sql_insert_data="INSERT INTO quiz (ad_id,quiz_department,quiz_course,quiz_sem,quiz_class,quiz_start,quiz_end,quiz_number,quiz_subject) 
							  VALUES ('$id','$dep','$course','$sem','$class','$start','$end','$num','$sub')";
		    $insert_data=mysql_query($sql_insert_data);
		?><div align="center">
 	 	<p>&nbsp;</p>
 	 	<p>&nbsp;</p>
 	 	<table width="780" border="1" bordercolor="#999999" bgcolor="#999999">
    		<tr>
      		<td bgcolor="#000000"><div align="center" class="style1">
       		  <p>&nbsp;</p>
        		<p class="style5">Quiz has been successfully register</p>
       		 <p>&nbsp;</p>
    		  </div></td>
 	  		 </tr>
 		 </table>
		 <p>&nbsp;</p>
 		 <p>&nbsp;</p>
 		 <p>&nbsp;</p>
		</div><?php
		}
		else
		{
			?><div align="center">
 	 		<p>&nbsp;</p>
 	 		<p>&nbsp;</p>
 	 		<table width="780" border="1" bordercolor="#999999" bgcolor="#999999">
    			<tr>
      			<td bgcolor="#000000"><div align="center" class="style1">
      	 		  <p>&nbsp;</p>
        			<p class="style5">Registration unsuccessful.  Please fill all the fields</p>
       			 <p>&nbsp;</p>
    			  </div></td>
 	  			 </tr>
 			 </table>
			 <p>&nbsp;</p>
 			 <p>&nbsp;</p>
 			 <p>&nbsp;</p>
			</div><?php
		}
	}
	else {
?>	

<table width="780" border="0" align="center">
  <tr>
    <td><p align="center" class="style4">QUIZ REGISTRATION FORM</p>
		<form method="POST" action="quiz_reg_date.php">
      <table width="551" border="0" align="center">
      <tr>
        <td width="202" class="style6">Department</td>
        <td width="10" class="style6">:</td>
		<?php 
			$sql_get_dep="SELECT ad_department FROM admin WHERE ad_no='$id'";
			$get_ad=mysql_query($sql_get_dep);
			$dep=mysql_fetch_assoc($get_ad);
			$dep=$dep['ad_department'];
			$sql_get_depname="SELECT dep_name FROM deparment WHERE dep_code='$dep'";
			$get_depname=mysql_query($sql_get_depname);
			$dep_name=mysql_fetch_assoc($get_depname);
			$dep_name=$dep_name['dep_name'];
			$sql_get_subject="SELECT * FROM subject WHERE sub_department='$dep'";
			$result4=mysql_query($sql_get_subject);
			$num_row=mysql_num_rows($result4);
		?>
        <td width="330" class="style3"><input name="dep" type="text" id="dep" value="<?php echo $dep_name; ?>" size="50" readonly="true"></td>
      </tr>
      <tr>
        <td class="style6">Quiz Subject </td>
        <td class="style6">:</td>
        <td class="style3"><span class="style7">
          <select name="sub" id="sub">
            <option></option>
            <?php if ($num_row>0) {
			  while ($sub = mysql_fetch_assoc($result4)) { ?>
            <option value="<?php echo $sub['sub_code']; ?>"><?php echo $sub['sub_name']; ?></option>
            <?php } }else { ?>
             <option>No Subject registered</option>
             <?php } ?>
          </select>
        </span> </td>
      </tr>
      <tr>
        <td class="style6">Course</td>
        <td class="style6">:</td>
		<?php 
			$sql_get_course="SELECT * FROM course ORDER BY course_code ASC";
			$get_course=mysql_query($sql_get_course);
		?>
		<td class="style3"><span class="style7">
		  <select name="course" id="course">
		    <option></option>
		    <?php while ($course=mysql_fetch_assoc($get_course)) { ?>
		    <option value="<?php echo $course['course_code']; ?>"><?php echo $course['course_name']; ?></option>
		    <?php } ?>
		    </select>
		  </span> </td>
      </tr>
      <tr>
        <td class="style6">Semester</td>
        <td class="style6">:</td>
		<?php 
			$sql_get_sem="SELECT * FROM semester ORDER BY sem_num ASC";
			$get_sem=mysql_query($sql_get_sem);
		?>
        <td class="style3"><span class="style7">
          <select name="sem" id="sem">
            <option></option>
            <?php while ($sem=mysql_fetch_assoc($get_sem)) { ?>
            <option value="<?php echo $sem['sem_num']; ?>"><?php echo $sem['sem_num']; ?></option>
            <?php } ?>
          </select>
        </span> </td>
      </tr>
      <tr>
        <td class="style6">Class</td>
        <td class="style6">:</td>
        <td class="style3"><span class="style7">
          <select name="class" id="class">
            <option value="A">A</option>
            <option value="B">B</option>
            <option value="C">C</option>
          </select>
        </span> </td>
      </tr>
      <tr>
        <td class="style6">Quiz Number </td>
        <td class="style6">:</td>
        <td class="style3"><input name="num" type="text" id="num" size="1" maxlength="1" /></td>
      </tr>
      <tr>
        <td class="style6">Date Start </td>
        <td class="style6">:</td>
        <td class="style6"><input name="start" type="text" id="start"> 
          example: yyyy-mm-dd </td>
      </tr>
      <tr>
        <td class="style6">Time to start </td>
        <td class="style6">:</td>
        <td class="style6"><input name="t_start" type="text" id="t_start">
          example: HH:MM:SS </td>
      </tr>
      <tr>
        <td class="style6">Date End </td>
        <td class="style6">:</td>
        <td class="style6"><input name="end" type="text" id="end"> 
          example: yyyy-mm-dd </td>
      </tr>
      <tr>
        <td class="style6">Time to end </td>
        <td class="style6">:</td>
        <td class="style6"><input name="t_end" type="text" id="t_end">
          example: HH:MM:SS </td>
      </tr>
    </table>
      <BR>
      <p align="center">
        <input type="submit" name="Submit" value="Submit">
         <input type="reset" name="reset" value=" Reset ">
      </p>
		</form>
	<p>&nbsp;</p></td>
  </tr>
</table>
<?php } ?>

<?php require_once ("footer.php"); ?>
